//unordered_map的使用
#include <iostream>
#include <unordered_map>
using namespace std;

class Name {
	Name(const string& forename = "", const string& surname = "") :m_forname(forename), m_surname(surname) {
	}
	bool operator==(const Name& that)const {
		return m_forname == that.m_forname && m_surname == that.m_surname;
	}
public:
private:
	string m_forname;//姓
	string m_surname;//名
	friend ostream& operator<<(ostream & os, const Name & name);
	friend class NameHash;
	friend class NameEqual;
};
ostream& operator<<(ostream& os, const Name& name) {
	return os<< name.m_forname << name.m_surname;
}
//哈希类
class NameHash {
public:
	size_t operator()(const Name& name)const {
		hash<string> hs;
		return hs(name.m_forname) ^ hs(name.m_surname << 1);
	}
};

//判等类
class NameEqual {
public:
	bool operator()(const Name& a, const Name& b)const {
		return a.m_forname == b.m_forname && a.m_surname == b.m_surname;
	}

};

int main(void) {
	unordered_map<Name, int,NameHash,NameEqual> um{
		{"张","飞",88},{"zhao","yun",85},{"guan","yu",90}
	};
	for (const auto& p : um) {
		cout << p.first << ":" << p.second << endl;
	}
	//unordered_map<string, int> um{
	//	{"张飞",88},{"zhaoyun",85},{"guanyu",90}
	//};
	//cout << um["zhaoyun"] << endl;
	//hash<string> hs;//哈希器
	//for (const auto& p : um) {
	//	cout << p.first << "(" << hs(p.first) << ")" << ":" << p.second << endl;
	//}
	return 0;
}